﻿using System;
using System.Collections.Generic;
using System.Text;
using DreamShield.Deployment.Miles.ApplicationUtils.ContextSwitch;
using System.Reflection;
using DreamShield.Deployment.Miles.ApplicationUtils;

namespace MiniTest
{
    class Program
    {
        static void Main(string[] args)
        {
            DreamShieldRuntimeConnect connect = DreamShieldRuntimeConnect.Singleton;

            Console.WriteLine(connect.RuntimeVersion.ToString());

            InstalledApplicationManager installedApplication = new InstalledApplicationManager(
                new Guid("1d7c0623-d3d9-488e-acca-74b8830b2dec"));
            Console.WriteLine(installedApplication.ToString());

            int installedLiveUpdate = InstalledApplicationManager.GetInstalledLiveUpdateVersion();
            if (installedLiveUpdate < 2)
            {
                Console.WriteLine("La version 2 de DreamShield's LiveUpdate est requise pour cette opération");
            }
            else
            {
                try
                {
                    string publishUrl = "http://smyley.developpez.com/programs/ms-net/sudoku/installer";
                    if (!installedApplication.HasUpdatesAvailable(publishUrl, true))
                    {
                        Console.WriteLine("Pas de mises à jour");
                    }
                    else
                    {
                        Console.WriteLine("Mises à jour trouvées"); 
                        installedApplication.ProposeUpdates(publishUrl);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Erreur. La bonne version de DreamShield's LiveUpdate n'est peut être pas installée");
                    Console.WriteLine(ex.ToString());
                }
            }

            Console.ReadLine();
        }
    }
}
